package com.cool.frm.demo.vo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Email;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Component
/**
 * 告诉springboot将本类中的属性，同配置文件中的属性进行绑定
 * prefix属性，指定配置中属性同本类中属性，进行一一对应
 *
 * 注：
 *  1、默认从全局配置文件中获取
 *  2、@value
 *      a、支持批量注入
 *      b、支持松散绑定
 *      c、不支持SpEL
 *      d、支持JSR30数据校验，@Validated，@Email等
 *      e、支持复杂类型封装
 *  3、@ConfigurationProperties
 *      a、一个一个注入
 *      b、不支持松散绑定
 *      c、支持SpEL
 *      d、不支持JSR30数据校验
 *      e、不支持复杂类型封装
 *
 */
@ConfigurationProperties(prefix = "person")
@Validated
public class TestVO implements Serializable {
    /**
     *
     */
//    @Value(value = "zhangsan")
    private String name;
    private int age;
    @Email
    private String email;
    private boolean boss;
    private String birth;
    private Map<String, String> maps1;
    private Map<String, String> maps2;
    private List<String> list1;
    private List<String> list2;
    private Dog dog;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isBoss() {
        return boss;
    }

    public void setBoss(boolean boss) {
        this.boss = boss;
    }

    public String getBirth() {
        return birth;
    }

    public void setBirth(String birth) {
        this.birth = birth;
    }

    public Map<String, String> getMaps1() {
        return maps1;
    }

    public void setMaps1(Map<String, String> maps1) {
        this.maps1 = maps1;
    }

    public Map<String, String> getMaps2() {
        return maps2;
    }

    public void setMaps2(Map<String, String> maps2) {
        this.maps2 = maps2;
    }

    public List<String> getList1() {
        return list1;
    }

    public void setList1(List<String> list1) {
        this.list1 = list1;
    }

    public List<String> getList2() {
        return list2;
    }

    public void setList2(List<String> list2) {
        this.list2 = list2;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    @Override
    public String toString() {
        return "TestVO{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", email='" + email + '\'' +
                ", boss=" + boss +
                ", birth='" + birth + '\'' +
                ", maps1=" + maps1 +
                ", maps2=" + maps2 +
                ", list1=" + list1 +
                ", list2=" + list2 +
                ", dog=" + dog +
                '}';
    }
}
